package com.zkzx.company.base.controller;

import com.zkzx.common.truck.command.TruckCommand;
import com.zkzx.common.truck.model.CompanyTruckVO;
import com.zkzx.common.truck.model.TruckListVO;
import com.zkzx.common.truck.param.TruckFilterParam;
import com.zkzx.common.truck.vo.TruckStatisticsVO;
import com.zkzx.common.vo.PageResult;
import com.zkzx.common.vo.RequestFilterParams;
import com.zkzx.company.base.service.CompanyTruckService;
import com.zkzx.util.json.JSONResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/10/15:26
 * @Description:
 */

@RestController
@Validated
@Api( tags="企业司机管理")
@RequestMapping(value = "/company_trucks")
public class CompanyTruckController extends BaseController{

    @Autowired
    private CompanyTruckService companyTruckService;

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取企业id", notes = "获取企业id")
    public PageResult<TruckListVO> find(@RequestParam("filterParam") String filterParamJson,
                                        @RequestParam("params") String paramsJson)  {

        TruckFilterParam filterParam = (TruckFilterParam) JSONResultUtil.toObject(filterParamJson, TruckFilterParam.class);
        RequestFilterParams params = (RequestFilterParams) JSONResultUtil.toObject(paramsJson, RequestFilterParams.class);


        return companyTruckService.find(filterParam,params,super.getCompanyId());
    }

    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取关联企业信息", notes = "获取关联企业信息")
    public List<CompanyTruckVO> getByIdCompanyId(@RequestParam("truck_id")Integer truckId, @RequestParam("company_id")Integer companyId)  {

        return companyTruckService.getByTruckIdAndCompanyId(truckId, companyId);
    }

    @PutMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "更新中间表", notes = "更新中间表")
    public void  update(@RequestBody @Valid TruckCommand command)  {
        companyTruckService.addOrUpdate(command,super.getCompanyId());
    }



    @GetMapping("/statistics")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取车辆数量信息", notes = "获取车辆数量信息")
    public TruckStatisticsVO getTruckStatistics(@RequestParam("company_id")Integer companyId)  {

        return companyTruckService.getTruckStatistics( companyId);
    }

}
